<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>商城管理系统</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="http://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jqprint.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.4.5/angular.min.js"></script>
<style>
.box_content {
	height: 100px;
}

.listTr button {
	border-radius: 6px;
	background-color: #337ab7;
	color: #ffffff；outline:none
}

.pageChange {
	float: right;
	color: #337ab7;
}

.pageChange>span {
	cursor: pointer
}

.pageChange>span:hover {
	color: blue
}
</style>
</head>
<body>


	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>发货管理</span>
					</div>
					<form id="deliveryform" class="form-inline"
						style="margin-top: 30px;margin-left: 20px">
						<div class="form-group">
							<label for="orderCode"> 订单编号:</label> <input type="text"
								class="form-control" name="orderFormId" id="orderFormId"
								placeholder="">
						</div>
						<input style="display:none" value="8" name="pageCount"
							id="pageCount" />
						<div class="form-group">
							<label for="ProductName">消费者:</label> <input type="text"
								class="form-control" name="userName" id="userName">
						</div>
						<div class="form-group">
							<label for="phone"> 消费者电话:</label> <input type="text" id="phone"
								class="form-control" placeholder="">
						</div>
						<button type="button" onclick="selectinfo()"
							class="btn btn-primary">查询</button>
					</form>
				</div>
				<div class="force-overflow1-1">
					<table id="showtable"
						class="table table-condensed table-bordered table-hover"
						style="text-align: center">
						<tr style="background-color:#59c7d2">
							<th style="text-align: center">序号</th>
							<th style="text-align: center">订单编号</th>
							<th style="text-align: center">顾客</th>
							<th style="text-align: center">送货地址</th>
							<th style="text-align: center">联系电话</th>
							<th style="text-align: center">订单时间</th>
							<th style="text-align: center">付款方式</th>
							<th style="text-align: center">订单总金额</th>
							<th style="text-align: center">订单详情</th>
							<th style="text-align: center">操作</th>
						</tr>
					</table>
					<div class="bgBox" style="visibility:hidden">
						<div id="box">
							<div class="box_header textYellow">
								<span>详细资料</span>
							</div>
							<div class="scrollbar1-2" id="style1-1">
								<div class="box_content">
									<table class="table table-condensed table-bordered table-hover"
										style="text-align: center" id="showtable2">
										<tr>
											<th style="text-align: center">产品名称</th>
											<th style="text-align: center">产品单价</th>
											<th style="text-align: center">产品数量</th>
											<th style="text-align: center">产品总价</th>
										</tr>
									</table>
								</div>
								<div class="force-overflow1-2"></div>
							</div>
							<div class="box_footer">
								<ul>
									<li id="sureDetail" onclick="motaiHidden()">确认</li>
									<li id="prints" onclick="prints()">打印</li>
								</ul>
							</div>
						</div>
					</div>
					<div class="pageChange">
						<span onclick="prePage()">&nbsp;&nbsp;上一页&nbsp;&nbsp;</span> <span
							onclick="nextPage()">&nbsp;&nbsp;下一页&nbsp;&nbsp;</span> <em>
							&nbsp; 第&nbsp;<span id="pageNum">1</span>&nbsp;页&nbsp;&nbsp;
						</em> <em>/&nbsp;&nbsp;共&nbsp;<span id="totalpage"></span>&nbsp;页
						</em> <em>&nbsp;&nbsp;&nbsp;跳到第<input id="searchInput"
							style="width:46px" maxlength="4" type="text">页
						</em>
						<button class="btn btn-primary" onclick="searchPage()">搜索</button>
					</div>
				</div>
			</div>
		</section>
	</div>
	<script type="text/javascript">
		function showMotais() { //弹出详情页面
			$(".bgBox").css("visibility", "visible")
		}
		function motaiHidden() { //隐藏详情页面
			$(".bgBox").css("visibility", "hidden")
		}
	
		$(function() {
			selectinfo()
		})
	
		
	
		function selectinfo() {
			var orderFormId = $("#orderFormId").val();
			var userName = $("#userName").val();
			var phone = $("#phone").val();
			var pageNum = $("#pageNum").html();
			var pageCount = $("#pageCount").val();
			$.post(urls + "orderFormAction/getOrderFormBySuper",
				{
					orderFormId : orderFormId,
					userName : userName,
					superId : localStorage.getItem("id"),
					pageNum : pageNum,
					pageCount : pageCount,
					phone : phone,
					status : 1
				},
				function(data) {
					//console.log(data)
					if (data) {
						var totalpage = data.totalpage;
						var orderlist = data.orderlist;
						var table = $("#showtable");
						$("tr").remove(".addtr");
						for (var i = 0; i < orderlist.length; i++) {
							var payWays;
							if (orderlist[i].paymentType == 1) {
								payWays = "货到付款"
							} else {
								payWays = "在线支付"
							}
							var append = "<tr class='addtr'><td>" + (i + 1) + "</td>" +
								"<td >" + orderlist[i].orderFormId + "</td>" +
								"<td>" + orderlist[i].userName + "</td>" +
								"<td>" + orderlist[i].address + "</td>" +
								"<td>" + orderlist[i].phone + "</td>" +
								"<td>" + orderlist[i].orderFormTime + "</td>" +
								"<td>" + payWays + "</td>" +
								"<td>" + orderlist[i].totalMoney + "</td>" +
								"<td><button class='btn btn-info' onclick='detailinfo(\""
								+ orderlist[i].orderFormId +
								"|$" + orderlist[i].totalMoney +
								"|$" + payWays +
								"|$" + orderlist[i].orderFormTime +
								"|$" + orderlist[i].shippingFee +
								"|$" + orderlist[i].userName +
								"|$" + orderlist[i].phone +
								"|$" + orderlist[i].address +
								"|$" + orderlist[i].inactive2 +
								"\")'>查看详情</button></td>" +
								"<td><button class='btn btn-primary' onclick='sendProduct(\"" + orderlist[i].orderFormId + "\")'>确认发货</button></td></tr>";
							table.append(append);
						}
						$("#totalpage").html(totalpage);
					}
				}
				, "json"
			)
		}
		function detailinfo(e) {
			showMotais()
			var arr = e.split("|$");
			$("#sendAdd").text(arr[7])
			$("#userPhones").text(arr[6])
			$("#users").text(arr[5])
			$("#orderTimes").text(arr[3])
			$("#payways").text(arr[2])
			$("#allMoney").text(arr[1])
			$("#shippingFees").text(arr[4])
			$("#superName").text(arr[8])
			$("#orderFormids").text(arr[0])
	
			$.post(urls + "orderFormAction/getOrderFormDetailsByOrderFormID",
				{
					orderFormId : arr[0]
				},
				function(res) {
					//console.log(res)
					var tables = $("#showtable2");
					var orderlist = res;
					$(".addtr2").empty();
					for (var i = 0; i < orderlist.length; i++) {
						var append = "<tr class='addtr2'><td >" + orderlist[i].productName + "</td>" +
							"<td>" + orderlist[i].unitPrice + "</td>" +
							"<td>" + orderlist[i].quantity + "</td>" +
							"<td>" + orderlist[i].totalPrices + "</td></tr>";
						tables.append(append);
					}
					var trs2 = $("#printsList");
					$(".addtr3").empty();
					for (var i = 0; i < orderlist.length; i++) {
						var append = "<tr class='addtr3'><td style='width:140px;text-align:center'>" + orderlist[i].productName + "</td>" +
							"<td style='width:40px;text-align:center'>" + orderlist[i].unitPrice + "</td>" +
							"<td style='width:40px;text-align:center'>" + orderlist[i].quantity + "</td>" +
							"<td style='width:60px;text-align:center'>" + orderlist[i].totalPrices + "</td></tr>";
						trs2.after(append);
					}
				}
			)
		}
		function motaiHidden() {
			$(".bgBox").css("visibility", "hidden");
		}
		function sendProduct(orderId) { //点击发货时将商品订单id与用户id发送到后台
			$.post(urls + "orderFormAction/TheSupermarketDelivery", {
				orderFormID : orderId,
			}, function(res) {
				if (res == true) {
					alert("发货成功")
					selectinfo()
				} else {
					alert("发货失败")
				}
			})
		}
	</script>
	<script type="text/javascript">
		(function($) {
			var printAreaCount = 0;
			$.fn.printArea = function() {
				var ele = $(this);
				var idPrefix = "printArea_";
				removePrintArea(idPrefix + printAreaCount);
				printAreaCount++;
				var iframeId = idPrefix + printAreaCount;
				var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
				iframe = document.createElement('IFRAME');
				$(iframe).attr({
					style : iframeStyle,
					id : iframeId
				});
				document.body.appendChild(iframe);
				var doc = iframe.contentWindow.document;
				$(document).find("link").filter(function() {
					return $(this).attr("rel").toLowerCase() == "stylesheet";
				}).each(function() {
					doc.write('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
				});
				doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
				doc.close();
				var frameWindow = iframe.contentWindow;
				frameWindow.close();
				frameWindow.focus();
				frameWindow.print();
			}
			var removePrintArea = function(id) {
				$("iframe#" + id).remove();
			};
		})(jQuery);
		function prints() {
			$("#printContent").printArea()
	
		}
	</script>
	<div id="printContent"
		style="width: 280px; margin:0 auto;display:none; ">
		<table style="width: 280px;font-size: 17px;font-family: 微软雅黑;">
			<tr>
				<td colspan="4"><p>&nbsp;</p></td>
			</tr>
			<tr>
				<td colspan="4" style="text-align: center;width: 280px;"><span
					id="superName"></span></td>
			</tr>
			<tr>
				<td colspan="4"><p>&nbsp;</p></td>
			</tr>

			<tr>
				<td colspan="4"></td>
			</tr>
			<tr>
				<td colspan="4" id="oid1234" style="width: 280px;">订单编号:<span
					id="orderFormids"></span></td>
			</tr>
			<tr>
				<td colspan="4">----------------------------------------</td>
			</tr>
			<tr>
				<td style="width:130px;text-align: center;">名称</td>
				<td style="width:40px;text-align: center;">单价</td>
				<td style="width:40px;text-align: center;">数量</td>
				<td style="width:70px;text-align: center;">金额</td>
			</tr>
			<tr>
				<td colspan="4">----------------------------------------</td>
			</tr>
			<tr id="printsList">
			</tr>
			<tr>
				<td colspan="4">----------------------------------------</td>
			</tr>
			<tr>
				<td colspan="4">如商品有问题请当面退换，</td>
			</tr>
			<tr>
				<td colspan="4">确认收货后不再退换。</td>
			</tr>
			<tr>
				<td colspan="4">谢谢惠顾！</td>
			</tr>
			<tr>
				<td colspan="4">----------------------------------------</td>
			</tr>
			<tr>
				<td colspan="4" id="peisongfei" style="width: 280px;">配送费：<span
					id="shippingFees"></span></td>
			</tr>
			<tr>
				<td colspan="4" id="summoney" style="width: 280px;">总金额：<span
					id="allMoney"></span></td>
			</tr>
			<tr>
				<td colspan="4" id="moneytype" style="width: 280px;">付款方式：<span
					id="payways"></span></td>
			</tr>
			<tr>
				<td colspan="4" id="time1234" style="width: 280px;">时间：<span
					id="orderTimes"></span></td>
			</tr>
			<tr>
				<td colspan="4" id="name1234" style="width: 280px;">联系人：<span
					id="users"></span></td>
			</tr>
			<tr>
				<td colspan="4" id="name1234" style="width: 280px;">联系电话：<span
					id="userPhones"></span></td>
			</tr>
			<tr>
				<td colspan="4" id="add1234" style="width: 280px;">送货地址：<span
					id="sendAdd"></span></td>
			</tr>
			<tr>
				<td colspan="4"><p>&nbsp;</p></td>
			</tr>
			<tr>
				<td colspan="4"><p>&nbsp;</p></td>
			</tr>
			<tr>
				<td colspan="4">----------------------------------------</td>
			</tr>
		</table>
	</div>
</body>
</html>